﻿#include "mainwindow.h"
#include "epowerapp.h"
#include "form485.h"
#include "com_manager.h"
#include "mhelper.h"
#include "topo_info.h"
#include "plug_info.h"
#include "dialog_select_com.h"

#include <QApplication>
#include <QFile>
#include <QTextCodec>
#include <nuf_bus_info.h>
#include <gpio_info.h>
#include "net_mgr.h"

//#define SERIAL


#ifdef Q_CC_MSVC
#pragma execution_character_set("utf-8")
#endif


int main(int argc, char* argv[])
{
    EPowerApp a(argc, argv);

    a.setApplicationName("电气综合管理单元样机软件");
    a.setApplicationVersion("1.0.0.6");
    a.setOrganizationName("hanlandtech");
    a.setOrganizationDomain("http://www.hanlandtech.com/");

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
	//设置中文编码
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
	QTextCodec* codec = QTextCodec::codecForName("GBK");
#else
	QTextCodec* codec = QTextCodec::codecForName("UTF-8");
#endif
	QTextCodec::setCodecForLocale(codec);
	QTextCodec::setCodecForCStrings(codec);
	QTextCodec::setCodecForTr(codec);
#else
	QTextCodec* codec = QTextCodec::codecForName("UTF-8");
	QTextCodec::setCodecForLocale(codec);
#endif


    //加载主题
     QFile styleFile(":/skin/darkstyle/darkstyle.qss");
   // QFile styleFile(":/skin/vs_dark.qss");

	//QFile styleFile(":/styles/style.qss");

     styleFile.open(QIODevice::ReadOnly);
     QString styles = styleFile.readAll();
     a.setStyleSheet(styles);
     styleFile.close();


    a.setFont(QFont(QStringLiteral("Microsoft YaHei UI"), 10));//设置字体


	NetMgr::init_net();

#ifdef SERIAL
    com_manager::instance()->enum_com();

    DialogSelectCom dlg;

    if ( dlg.exec() != QDialog::Accepted)
        return 0;

    PlugInfo::loadSetting();

    NufBusSetting::loadSetting();

    if (1)
    {
        QString com_name = com_manager::instance()->curComName;//comList.first();
        rs232com* rs232=   com_manager::instance()->get_com(com_name);
        if (rs232 == NULL)
            return 0;
      //  TopoInfo::Instance()->query_node_info();
    }
    else
    {
       TopoInfo::Instance()->loadSetting();
    }
   TopoInfo::Instance()->save_topo_setting();
#endif
     // Form485 form485;
     // form485.show();

    // FormSerial formSerial;
    // formSerial.show();

      MainWindow w;

      w.show();
      return a.exec();
}
